﻿using System;
using System.Collections.Generic;
using XCI.Sys.Model;
using XCI.Core;
using XCI.Windows.Extensions;
using XCI.Sys.Filter;

namespace XCI.Sys.Service
{
    /// <summary>
    /// 系统历史记录服务
    /// </summary>
    public class HistoryService : BaseService<SysHistory>
    {
        public static readonly HistoryService Instance = new HistoryService();
        protected override string RootUrl => "/api/sys/history/";

        /// <summary>
        /// 根据主键获取历史记录对象
        /// </summary>
        /// <param name="id">历史记录主键</param>
        public SysHistory SelectById(string id)
        {
            return SelectByIdCore(id);
        }

        /// <summary>
        /// 根据记录主键查询最后一条历史记录
        /// </summary>
        /// <param name="primaryKey">业务记录主键</param>
        public SysHistory SelectLastByPrimaryKey(string primaryKey)
        {
            var url = GetUrl("selectLastByPrimaryKey", primaryKey);
            return SysRuntime.Api.Post<SysHistory>(url).EnsureSuccess().Data;
        }

        /// <summary>
        /// 根据业务记录主键查询历史分页列表
        /// </summary>
        /// <param name="paged">分页参数</param>
        /// <param name="primaryKey">业务记录主键</param>
        public PageList<SysHistory> SelectByPrimaryKey(PageParam paged, string primaryKey)
        {
            var url = GetUrl("selectByPrimaryKey", primaryKey);
            var map = ToPageMap(paged);
            return SysRuntime.Api.Post<PageList<SysHistory>>(url, map).EnsureSuccess().Data;
        }

        /// <summary>
        /// 查询历史记录分页列表
        /// </summary>
        /// <param name="paged">分页参数</param>
        /// <param name="filter">历史记录过滤条件</param>
        public PageList<SysHistory> SelectPageList(PageParam paged, HistoryFilter filter)
        {
            var map = ToPageMap(paged).AddObject(filter);
            return SelectPageListCore(map);
        }
    }
}
